#
#   __init__.py.py
#   journalismManger
#
#   Created by luoxh on 2019-07-22-09:57.
#   Copyright © 2019 luoxh. All rights reserved.
#
from functools import wraps

from src.extension.auth import verify_session_msg
from src.extension.exceptions import CustomException
from src.extension.status import CustomStatus


def login_required():
    def wrapper(fn):
        @wraps(fn)
        def decorator(*args, **kwargs):
            try:
                if not verify_session_msg('session_id'):
                    raise CustomException(CustomStatus.SESSION_ID_DOES_TAMPER)
            except KeyError:
                raise CustomException(CustomStatus.SESSION_ID_NOT_EXIST)
            return fn(*args, **kwargs)

        return decorator

    return wrapper
